package com.mango.leet.code.week1.game387;

import java.util.*;
import java.util.concurrent.LinkedBlockingDeque;

/**
 * https://leetcode.cn/contest/weekly-contest-387/problems/distribute-elements-into-two-arrays-i/
 * @Author: mango
 * @Date: 2024/3/9 22:15
 */
public class LC3069 {
    public int[] resultArray(int[] nums) {
        Deque<Integer> list1 = new LinkedBlockingDeque<>();
        Deque<Integer> list2 = new LinkedBlockingDeque<>();
        list1.addLast(nums[0]);
        list2.addLast(nums[1]);
        for (int i = 2; i < nums.length; i++) {
            if (list1.getLast() > list2.getLast()) {
                list1.addLast(nums[i]);
            } else {
                list2.addLast(nums[i]);
            }
        }
        List<Integer> result = new ArrayList<>();
        result.addAll(list1);
        result.addAll(list2);
        int[] result2 = new int[result.size()];
        for (int i = 0; i < result.size(); i++) {
            result2[i] = result.get(i);
        }
        return result2;
    }

    public static void main(String[] args) {

    }
}
